home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / lib / mkmf / mkmf.command < prev    next >
Encoding:
Text File  |  1992-10-12  |  3.0 KB  |  106 lines

  1. #!/sprite/cmds/csh -f
  2. #
  3. # A script to generate (or regenerate) a source (cmds) directory  Makefile
  4. # from a prototype Makefile.  If ./Makefile.proto exists, use it, else
  5. # use a common prototype.
  6. #
  7. # We assume we were invoked from mkmf, thus we don't need to alter the
  8. # path, and MKMFDIR is in the environment to tell us where to find prototype
  9. # makefiles, etc.
  10. #
  11. # Parameters passed in from mkmf as environment variables:
  12. #
  13. #    DOMACHINES    names of machines we are supposed to run mkmf on
  14. #    MKMFDIR        directory containing prototype makefiles
  15. #    MKMFFLAGS    arguments to all mkmfs run recursively
  16. #    MACHINES    list of machine names (e.g. "sun2 sun3"), for
  17. #            which there are machine-dependent subdirectories
  18. #            (sun2.md, sun3.md) to hold the object files and
  19. #            any machine-specific source files to use when
  20. #            compiling for that machine
  21. #    MAKEFILE    name of makefile to create
  22. #    SUBTYPE        information about what type of command this is:
  23. #            used to figure out where to install things.
  24. #
  25. # Several of these environment variables must be copied to local shell
  26. # variables before use, because shell variables can be used in some places
  27. # where environment variables can't.
  28.  
  29. #
  30. # Argument processing.  (Generalized form, even though just one flag so far.)
  31. #
  32. while ($#argv >= 1)
  33.     if ("$1" == '-x') then
  34.     set echo
  35.     endif
  36.     shift
  37. end
  38.  
  39. set nonomatch
  40. set srcs =(*.{h,c,s,l,y,cc} *.md/*.{h,c,s,l,y,cc,o})
  41. set mds = (*.md)
  42. set manPages = (*.man)
  43. if ("$mds" == "*.md") then
  44.     set mds = ()
  45. endif
  46. if ("$manPages" == "*.man") then
  47.     set manPages = ()
  48. endif
  49. #
  50. # Check to see if there were any sources.  The first check (size == 2, the
  51. # number of strings that would be there if there were no matches)
  52. # is only necessary because the second check will cause an error if
  53. # srcs contains more than 1024 bytes.  If no sources, then assume that
  54. # this directory contains only a shell script (and eliminate any
  55. # machine-dependent subdirectories that Pmake might have created).
  56. #
  57. if ($#srcs == 2) then
  58.     if ("$srcs" == "*.{h,c,s,l,y,cc} *.md/*.{h,c,s,l,y,cc,o}") unset srcs
  59. endif
  60. unset nonomatch
  61. if (! $?srcs) then
  62.     echo "No sources, assuming shell script."
  63.     if ("$mds" != "") then
  64.     echo "Deleting extraneous subdirectories $mds."
  65.     rmdir $mds
  66.     if ($status != 0) then
  67.         echo "Error removing directories: not empty."
  68.         exit 1
  69.     endif
  70.     endif
  71.     $MKMFDIR/mkmf.script $*
  72.     exit $status
  73. endif
  74.  
  75. set subtype=$SUBTYPE
  76. set prog=$cwd:t
  77. set machines=($MACHINES)
  78. set domachines = ($DOMACHINES)
  79. set makefile=($MAKEFILE)
  80. set distdir=($DISTDIR)
  81.  
  82. if (-e $makefile.proto) then
  83.     set proto=$makefile.proto
  84. else
  85.     set proto="${MKMFDIR}/Makefile.command"
  86. endif
  87.  
  88. echo "Generating $makefile for $prog using $proto"
  89.  
  90.  
  91. cat $proto | sed \
  92.     -e "s,@(DATE),`date`,g" \
  93.     -e "s,@(MACHINES),$machines,g" \
  94.     -e "s,@(MAKEFILE),$makefile,g" \
  95.     -e "s,@(MANPAGES),$manPages,g" \
  96.     -e "s,@(NAME),$prog,g" \
  97.     -e "s,@(TEMPLATE),$proto,g" \
  98.     -e "s,@(TYPE),$subtype,g" \
  99.     -e "s,@(DISTDIR),$distdir,g" \
  100.     > $makefile
  101.  
  102. setenv PARENTDIR $cwd
  103. foreach i ($domachines)
  104.     (cd $i.md; mkmf $MKMFFLAGS -f md.mk)
  105. end
  106.